<?php

namespace app\socket\controller;

use Workerman\Worker;
use GatewayWorker\Register;
use GatewayWorker\BusinessWorker;
use GatewayWorker\Gateway;
//控制器无需继承Controller

class ConfigController{

    /**
     * 构造函数
     * @access public
     */
    public function __construct()
    {
        //初始化各个GatewayWorker
        //初始化register
        new Register('text://0.0.0.0:1237');

        //初始化 bussinessWorker 进程
        $worker = new BusinessWorker();
        $worker->name = 'BusinessWorker';
        $worker->count = 4;
        $worker->registerAddress = '127.0.0.1:1237';
        //设置处理业务的类,此处制定Events的命名空间
        $worker->eventHandler = '\app\socket\controller\Events';
        // 初始化 gateway 进程
        $gateway = new Gateway("websocket://0.0.0.0:9092");
        $gateway->name = 'Gateway';
        $gateway->count = 4;
        // 心跳间隔
        $gateway->pingInterval = 20;
        // 1 客户端必须要反应  0 不需要
        $gateway->pingNotResponseLimit = 1;
        // 心跳数据
        $gateway->pingData = '{"type":"ping"}';
        $gateway->lanIp = '127.0.0.1';
        $gateway->startPort = 5900;
        $gateway->registerAddress = '127.0.0.1:1237';

        //运行所有Worker;
        Worker::runAll();
    }

}

